package com.weixin.paleituo.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.weixin.paleituo.activity.ImageViewActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Author yichao
 * Time  2017/12/1 16:45
 * Dest  房屋详情滑动
 */

public class HouseDetailPagerAdapter extends PagerAdapter {
    private Context nContext;
    private List<String> mList;

    public HouseDetailPagerAdapter(Context nContext, List<String> list) {
        this.nContext = nContext;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
       container.removeView((View) object);

    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, final int position) {
        ImageView imageView=new ImageView(nContext);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
      //  imageView.setImageResource(mList.get(position));
        Glide.with(nContext).load(mList.get(position)).into(imageView);
        container.addView(imageView);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ImageViewActivity.startActivity(nContext,(ArrayList<String>) mList,position);



            }
        });


        return imageView;
    }
}
